﻿using System;
using System.Collections.Generic;
using System.Text;
using DBList;
using DBList.Entities;
using System.Data.SqlClient;
using System.Data;

namespace DBAccessor.Accessor
{
    public class MsgAccessor
    {
		public int AddBarCode(string strBarCode, string strpwd, string strkind, string kindcode, string money, int bcflag, SqlConnection conn, SqlCommand cmd)
        {
			Int64	ubarcode=0;
			Decimal dMoney=0;
			Int64.TryParse(strBarCode, out ubarcode);
			Decimal.TryParse(money, out dMoney);
			if (strBarCode.Length < 10 || ubarcode < (Int64)89998999)
				return -10;
			SqlParameter[] sqlParameter = {
                 new SqlParameter("@barcode",SqlDbType.BigInt, 8),
                 new SqlParameter("@pwd",SqlDbType.NVarChar,50),
                 new SqlParameter("@kind",SqlDbType.NVarChar,20),
                 new SqlParameter("@kindcode",SqlDbType.NVarChar,10),
                 new SqlParameter("@price",SqlDbType.Money,8),
                 new SqlParameter("@bcflag",SqlDbType.Int, 4)
            };
			sqlParameter[0].Value = ubarcode;
			sqlParameter[1].Value = strpwd;
			sqlParameter[2].Value = strkind;
			sqlParameter[3].Value = kindcode;
			sqlParameter[4].Value = dMoney;
			sqlParameter[5].Value = bcflag;

			cmd.Parameters.Clear();
			cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
			cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
			SqlHelper.PrepareCommand(cmd, conn, null, CommandType.StoredProcedure, "AddBarCode", sqlParameter);
			int nRet = cmd.ExecuteNonQuery();
			int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nRet);
			cmd.Parameters.Clear();
            return	nRet;
        }
		public int UpdateBarCode(int nOpeID, string strtiaoma, int flownum, string customeinfo, string comment, string wlhao)
		{
			SqlCommand cmd = null;
			int nRet = -8;
			try
			{
				SqlParameter[] sqlParameter = {
					 new SqlParameter("@operater",SqlDbType.Int,4),
					 new SqlParameter("@barcode",SqlDbType.BigInt, 8),
					 new SqlParameter("@flownum",SqlDbType.Int,4),
					 new SqlParameter("@cosumerinfo",SqlDbType.NVarChar,80),
					 new SqlParameter("@comment",SqlDbType.NVarChar,50),
					 new SqlParameter("@wldanhao",SqlDbType.NVarChar,30)
	            };
				Int64 nBarCode = 0;
				Int64.TryParse(strtiaoma, out nBarCode);
				sqlParameter[0].Value = nOpeID;
				sqlParameter[1].Value = nBarCode;
				sqlParameter[2].Value = flownum;
				sqlParameter[3].Value = customeinfo;
				sqlParameter[4].Value = comment;
				sqlParameter[5].Value = wlhao;

				cmd = new SqlCommand();
				cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
				cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
				nRet = SqlHelper.ExecuteNonQuery(cmd, "UpdateBarCode", sqlParameter);
				int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nRet);
			}
			catch (System.Exception e)
			{
				if (cmd != null)
					cmd.Parameters.Clear();
				String strErr = e.Message;
				nRet = -8;
			}
			return nRet;
		}
		public int RevokePkupGoods(int nOpeID, string strtiaoma)
		{
			SqlCommand cmd = null;
			int nRet = -8;
			try
			{
				SqlParameter[] sqlParameter = {
					 new SqlParameter("@operater",SqlDbType.Int,4),
					 new SqlParameter("@barcode",SqlDbType.BigInt, 8)
	            };
				Int64 nBarCode = 0;
				Int64.TryParse(strtiaoma, out nBarCode);
				sqlParameter[0].Value = nOpeID;
				sqlParameter[1].Value = nBarCode;

				cmd = new SqlCommand();
				cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
				cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
				nRet = SqlHelper.ExecuteNonQuery(cmd, "RevokePkupGoods", sqlParameter);
				int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nRet);
			}
			catch (System.Exception e)
			{
				if (cmd != null)
					cmd.Parameters.Clear();
				String strErr = e.Message;
				nRet = -8;
			}
			return nRet;
		}
		public TiaoMaRecord GetOneTiaoMaRecord(string strtm, string strpwd)
		{
			Int64 nBarCode = 0;
			Int64.TryParse(strtm, out nBarCode);
			SqlParameter[] sqlparameter = {
                new SqlParameter("@tiaoma",SqlDbType.BigInt,8),
                new SqlParameter("@pwd",SqlDbType.NVarChar,50)
            };
			sqlparameter[0].Value = nBarCode;
			sqlparameter[1].Value = strpwd;
			TiaoMaRecord msgData = new TiaoMaRecord();
			SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "GetTiaoMaRecord", sqlparameter);
			if (reader.HasRows){
				reader.Read();

				DateTime _addtime = new DateTime(1900, 1, 1);
				int _flowctrl = 0;
				bool _isactived = false;
				int _activater = 0;
                DateTime _acttime = new DateTime(1900, 1, 1);
				int _tookid = 0;
				int _applier = 0;
                DateTime _applytime = new DateTime(1900, 1, 1); 
				int _confirmer = 0;
                DateTime _cnfmtime = new DateTime(1900, 1, 1);
				string _consumerinfo = string.Empty;
				string _wldanhao = string.Empty;
                string _strPassword = string.Empty;
				int _kind = 0, _nid = 0;

				int.TryParse(reader["ID"].ToString(), out _nid);
				DateTime.TryParse(reader["AddTime"].ToString(), out _addtime);
				int.TryParse(reader["FlowCtrl"].ToString(), out _flowctrl);
				bool.TryParse(reader["IsActivation"].ToString(), out _isactived);
				int.TryParse(reader["Activater"].ToString(), out _activater);
				DateTime.TryParse(reader["ActTime"].ToString(), out _acttime);
				int.TryParse(reader["TookID"].ToString(), out _tookid);
				int.TryParse(reader["Applier"].ToString(), out _applier);
				DateTime.TryParse(reader["ApplyTime"].ToString(), out _applytime);
				int.TryParse(reader["Conformer"].ToString(), out _confirmer);
				DateTime.TryParse(reader["CnfmTime"].ToString(), out _cnfmtime);
				_consumerinfo = reader["ConsumerInfo"].ToString();
				_wldanhao = reader["WLDanHao"].ToString();
                _strPassword = reader["PWD"].ToString();
				int.TryParse(reader["Kind"].ToString(), out _kind);

				msgData.CsterComment = reader["CstmerComt"].ToString();
				msgData.ID = _nid;
				msgData.TiaoMa = nBarCode;
                msgData.PWD = _strPassword;
				msgData.AddDate = _addtime;
				msgData.FlowID = _flowctrl;
				msgData.IsActivated = _isactived;
				msgData.Activater = _activater;
				msgData.ActTime = _acttime;
				msgData.TookID = _tookid;
				msgData.Applier = _applier;
				msgData.ApplyTime = _applytime;
				msgData.Confirmer = _confirmer;
				msgData.CnfmTime = _cnfmtime;
				msgData.ConsumerInfo = _consumerinfo;
				msgData.WLDanHao = _wldanhao;
				msgData.Kind = _kind;
			}
			reader.Close();
			reader.Dispose();
			return msgData;
		}
		public int PickupGoods(int nopeType, int operaterid, string strtiaoma, string strpwd, string consumerinfo, string strcomment)
		{
			SqlCommand cmd = null;
			int nRet = -8;
			try {
				SqlParameter[] sqlParameter = {
					 new SqlParameter("@opetype",SqlDbType.Int,4),
					 new SqlParameter("@operater",SqlDbType.Int,4),
					 new SqlParameter("@tiaoma",SqlDbType.BigInt,8),
					 new SqlParameter("@pwd",SqlDbType.NVarChar,50),
					 new SqlParameter("@cosumerinfo",SqlDbType.NVarChar,80),
					 new SqlParameter("@comment",SqlDbType.NVarChar,50)
	            };
				Int64 nBarCode = 0;
				Int64.TryParse(strtiaoma, out nBarCode);
				sqlParameter[0].Value = nopeType;
				sqlParameter[1].Value = operaterid;
				sqlParameter[2].Value = nBarCode;
				sqlParameter[3].Value = strpwd;
				sqlParameter[4].Value = consumerinfo;
				if (strcomment == null || strcomment.Length == 0)
					sqlParameter[5].Value = null;
				else sqlParameter[5].Value = strcomment;
				cmd = new SqlCommand();
				cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
				cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
				nRet = SqlHelper.ExecuteNonQuery(cmd, "PickupGoods", sqlParameter);
				int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nRet);
			}
			catch (System.Exception e){
				if (cmd != null)
					cmd.Parameters.Clear();
				String strErr = e.Message;
				nRet = -8;
			}
			return nRet;
		}

		public List<MDTJData> MDKFWLTJGoodsKind(string opeXMLParams, int nPageIndex, int nPageSize, int nSearchtype, int nFuncFlag, ref DateTime bdt, ref DateTime edt, out int outTotal)
		{
			List<MDTJData> list = new List<MDTJData>();

			outTotal = 0;
			SqlParameter[] sqlParamenter = { 
				new SqlParameter("@opeidarray",SqlDbType.NVarChar, 600),
				new SqlParameter("@pageIndex",SqlDbType.Int, 4),
				new SqlParameter("@pageSize",SqlDbType.Int, 4),
				new SqlParameter("@searchtype",SqlDbType.Int, 4),
				new SqlParameter("@outTotalSize",SqlDbType.Int, 4),
				new SqlParameter("@begintime",SqlDbType.DateTime, 8),
				new SqlParameter("@endtime",SqlDbType.DateTime, 8),
            };
			sqlParamenter[0].Value = opeXMLParams;
			sqlParamenter[1].Value = nPageIndex;
			sqlParamenter[2].Value = nPageSize;
			sqlParamenter[3].Value = nSearchtype;
			sqlParamenter[4].Value = outTotal;
			sqlParamenter[5].Value = bdt;
			sqlParamenter[6].Value = edt;
			sqlParamenter[4].Direction = ParameterDirection.Output;
			sqlParamenter[5].Direction = ParameterDirection.InputOutput;
			sqlParamenter[6].Direction = ParameterDirection.InputOutput;

            SqlCommand cmd = new SqlCommand();
            cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
            cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
			SqlDataReader read = null;
			if (nFuncFlag == 5)
	            read = SqlHelper.ExecuteReader(cmd, "MDTJTakeGoods", sqlParamenter);
			else if(nFuncFlag == 3)
				read = SqlHelper.ExecuteReader(cmd, "TJDownDan", sqlParamenter);
			else if(nFuncFlag == 4)
				read = SqlHelper.ExecuteReader(cmd, "HadSentGoodsTJ", sqlParamenter);
			bool bNextRDS = true;
			do {
				while (read != null && read.Read())
				{
				   MDTJData info = new MDTJData();
				   string strName = string.Empty;
				   int	nNumber = 0, nID = 0;
				   if (read["Name"].ToString() != null)
					   strName = read["Name"].ToString();
				   int.TryParse(read["nid"].ToString(), out nID);
				   if (strName != string.Empty || nID != 0){
					   int.TryParse(read["num"].ToString(), out nNumber);
					   Decimal dmoney = 0;
					   Decimal.TryParse(read["allmoney"].ToString(), out dmoney);

					   info.ID	= nID;
					   info.Name = strName;
					   info.Number = nNumber;
					   info.TotalMoney = dmoney;
					   if (Decimal.TryParse(read["Money"].ToString(), out dmoney)){
						   info.SingleMoney = dmoney;
					   }
					   info.Introduction = read["Introduction"].ToString();

					   list.Add(info);
					   bNextRDS = false;
				   }
			   }
			} while (read != null && bNextRDS && read.NextResult());//这里是关键－－－移动到下一个结果集
			if (read != null)
			{
				read.Close();
				read.Dispose();
			}
			//After Closing, the folowing can get.
			DateTime.TryParse(cmd.Parameters["@begintime"].Value.ToString(), out bdt);
			DateTime.TryParse(cmd.Parameters["@endtime"].Value.ToString(), out edt);
			int.TryParse(cmd.Parameters["@outTotalSize"].Value.ToString(), out outTotal);
			int nTmp = 0;
			int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nTmp);

			return list;
		}
		public List<MDTookDanTJData> GetMDTookDanTJ(string opeXMLParams, int nPageIndex, int nPageSize, int nSearchtype, ref DateTime bdt, ref DateTime edt, out int outTotal)
		{
			List<MDTookDanTJData> list = new List<MDTookDanTJData>();

			outTotal = 0;
			SqlParameter[] sqlParamenter = { 
				new SqlParameter("@opeidarray",SqlDbType.NVarChar, 600),
				new SqlParameter("@pageIndex",SqlDbType.Int, 4),
				new SqlParameter("@pageSize",SqlDbType.Int, 4),
				new SqlParameter("@searchtype",SqlDbType.Int, 4),
				new SqlParameter("@outTotalSize",SqlDbType.Int, 4),
				new SqlParameter("@begintime",SqlDbType.DateTime, 8),
				new SqlParameter("@endtime",SqlDbType.DateTime, 8),
            };
			sqlParamenter[0].Value = opeXMLParams;
			sqlParamenter[1].Value = nPageIndex;
			sqlParamenter[2].Value = nPageSize;
			sqlParamenter[3].Value = nSearchtype;
			sqlParamenter[4].Value = outTotal;
			sqlParamenter[5].Value = bdt;
			sqlParamenter[6].Value = edt;
			sqlParamenter[4].Direction = ParameterDirection.Output;
			sqlParamenter[5].Direction = ParameterDirection.InputOutput;
			sqlParamenter[6].Direction = ParameterDirection.InputOutput;

			SqlCommand cmd = new SqlCommand();
			cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
			cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
			SqlDataReader read = SqlHelper.ExecuteReader(cmd, "MDTookDanTJ", sqlParamenter);
			bool bNextRDS = true;
			do
			{
				while (read.Read())
				{
					MDTookDanTJData info = new MDTookDanTJData();
					string strName = read["Name"].ToString();
					int	nNumber = 0, nID = 0;
					int.TryParse(read["ID"].ToString(), out nID);
					if (strName != null || nID != 0)
					{
						info.Name = strName;
						info.ID = nID;
						bool bHasNum = false;
						strName = read["BeginNumber"].ToString();
						if (int.TryParse(strName, out nNumber))
						{
							info.BeginInt = nNumber;
							bHasNum = true;
						}
						strName = read["EndNumber"].ToString();
						if (int.TryParse(strName, out nNumber))
						{
							info.EndInt = nNumber;
							bHasNum = true;
						}
						strName = read["takednum"].ToString();
						if (int.TryParse(strName, out nNumber))
							info.TakedNum = nNumber;
						DateTime	tt;
						strName = read["TookTime"].ToString();
						if (DateTime.TryParse(strName, out tt))
							info.TookTime = tt;
						strName = read["Taker"].ToString();
						if (int.TryParse(strName, out nNumber))
							info.Taker = nNumber;
						info.TakerName = read["RealName"].ToString();
						info.Introduction = read["Introduction"].ToString();
						info.Comment = read["Comment"].ToString();
						Decimal	dPrice = 0;
						string strPrice = read["Money"].ToString();
						if (Decimal.TryParse(strPrice, out dPrice))
							info.SingleMoney = dPrice;
						if (bHasNum) {
							info.Number = info.EndInt - info.BeginInt + 1;
							info.TotalMoney = info.Number * dPrice;
						}
						info.SaledMoney = info.TakedNum * dPrice;

						list.Add(info);
						bNextRDS = false;
					}
				}
			} while (bNextRDS && read.NextResult());//这里是关键－－－移动到下一个结果集
			read.Close();
			read.Dispose();
			//After Closing, the folowing can get.
			DateTime.TryParse(cmd.Parameters["@begintime"].Value.ToString(), out bdt);
			DateTime.TryParse(cmd.Parameters["@endtime"].Value.ToString(), out edt);
			int.TryParse(cmd.Parameters["@outTotalSize"].Value.ToString(), out outTotal);
			int nTmp = 0;
			int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nTmp);

			return list;
		}
		public List<F123HisData> GetFlow123Detail(string opeXMLParams, int nPageIndex, int nPageSize, int nSearchtype, int nFlowFlag, ref DateTime bdt, ref DateTime edt, out int outTotal, string bcmatch, string cstmermatch, string strApplierThreef)
		{
			List<F123HisData> list = new List<F123HisData>();

			outTotal = 0;
			SqlParameter[] sqlParamenter = { 
				new SqlParameter("@opeidarray",SqlDbType.NVarChar, 600),
				new SqlParameter("@pageIndex",SqlDbType.Int, 4),
				new SqlParameter("@pageSize",SqlDbType.Int, 4),
				new SqlParameter("@searchtype",SqlDbType.Int, 4),
				new SqlParameter("@flowflag",SqlDbType.Int, 4),
				new SqlParameter("@outTotalSize",SqlDbType.Int, 4),
				new SqlParameter("@begintime",SqlDbType.DateTime, 8),
				new SqlParameter("@endtime",SqlDbType.DateTime, 8),
				new SqlParameter("@bcmatch",SqlDbType.NVarChar, 20),
				new SqlParameter("@cstmermatch",SqlDbType.NVarChar, 20),
				new SqlParameter("@applieridthreef",SqlDbType.Int, 4),
            };
			sqlParamenter[0].Value = opeXMLParams;
			sqlParamenter[1].Value = nPageIndex;
			sqlParamenter[2].Value = nPageSize;
			sqlParamenter[3].Value = nSearchtype;
			sqlParamenter[4].Value = nFlowFlag;
			sqlParamenter[5].Value = outTotal;
			sqlParamenter[6].Value = bdt;
			sqlParamenter[7].Value = edt;
			sqlParamenter[5].Direction = ParameterDirection.Output;
			sqlParamenter[6].Direction = ParameterDirection.InputOutput;
			sqlParamenter[7].Direction = ParameterDirection.InputOutput;
			if(bcmatch != null && bcmatch.Length > 0)
				sqlParamenter[8].Value = bcmatch;
			else sqlParamenter[8].Value = null;
			if (cstmermatch != null && cstmermatch.Length > 0)
				sqlParamenter[9].Value = cstmermatch;
			else sqlParamenter[9].Value = null;
			sqlParamenter[10].Value = null;
			if (strApplierThreef != null && strApplierThreef.Length > 0)
			{
				sqlParamenter[10].Value = int.Parse(strApplierThreef);
			}

			SqlCommand cmd = new SqlCommand();
			cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
			cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
			SqlDataReader read = SqlHelper.ExecuteReader(cmd, "GetFlow123Detail", sqlParamenter);
			bool bNextRDS = true;
			do
			{
				while (read.Read())
				{
					F123HisData info = new F123HisData();
					string strName = string.Empty;
					int	nID = 0;
					strName = read["KindName"].ToString();
					int.TryParse(read["nid"].ToString(), out nID);
					if (strName != null || nID != 0)
					{
						info.ID = nID;
						info.KindName = strName;
						Int64 nBarcode = 0;
						Int64.TryParse(read["TiaoMa"].ToString(), out nBarcode);
						info.BarCode = nBarcode;
						DateTime	tt; int	ntt;
						strName = read["ApplyTime"].ToString();
						if (DateTime.TryParse(strName, out tt))
							info.ApplyTime = tt;
						strName = read["CnfmTime"].ToString();
						if (DateTime.TryParse(strName, out tt))
							info.CnfmTime = tt;
						strName = read["Applier"].ToString();
						if (int.TryParse(strName, out ntt))
							info.ApplierID = ntt;
						strName = read["Conformer"].ToString();
						if (int.TryParse(strName, out ntt))
							info.CnfmerID = ntt;
						info.CustomerInfo = read["ConsumerInfo"].ToString();
						info.WLDanHao = read["WLDanHao"].ToString();
						strName = read["FlowCtrl"].ToString();
						if (int.TryParse(strName, out ntt))
						{
							info.FlowID = ntt;
							if (ntt == 1)
								info.FlowName = @"已提货";
							else if (ntt == 2)
							{
								info.FlowName = @"未发货";
							}
							else if (ntt == 3)
							{
								info.FlowName = @"已发货";
								info.FlowName += "[";
								if(info.WLDanHao == null || info.WLDanHao.Length == 0)
									info.FlowName += @"无";
								else
									info.FlowName += info.WLDanHao;
								info.FlowName += "]";
							}
						}
						Decimal dmoney = 0;
						strName = read["Money"].ToString();
						if (Decimal.TryParse(strName, out dmoney))
							info.SingleMoney = dmoney;
						info.CstmerComment = read["CstmerComt"].ToString();

						list.Add(info);
						bNextRDS = false;
					}
				}
			} while (bNextRDS && read.NextResult());//这里是关键－－－移动到下一个结果集
			read.Close();
			read.Dispose();
			//After Closing, the folowing can get.
			DateTime.TryParse(cmd.Parameters["@begintime"].Value.ToString(), out bdt);
			DateTime.TryParse(cmd.Parameters["@endtime"].Value.ToString(), out edt);
			int.TryParse(cmd.Parameters["@outTotalSize"].Value.ToString(), out outTotal);
			int nTmp = 0;
			int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nTmp);

			Dictionary<int, string> idRealName = new Dictionary<int, string>();
			for (int i = 0; i < list.Count; i++)
			{
				if(list[i].ApplierID == 0){
					list[i].ApplierName = @"网络下单";
				}
				else if(idRealName.ContainsKey(list[i].ApplierID)){
					list[i].ApplierName = idRealName[list[i].ApplierID];
				}
				else {
					MemberAccessor memAcce = new MemberAccessor();
					UserData memData = memAcce.GetMemberInfo(list[i].ApplierID);
					list[i].ApplierName = memData.RealName;
					list[i].MDAddress = memData.Address;
					list[i].MDIntroduction = memData.Introduction;
				}

				if (idRealName.ContainsKey(list[i].CnfmerID))
				{
					list[i].ConformerName = idRealName[list[i].CnfmerID];
				}
				else if (list[i].CnfmerID != 0)
				{
					MemberAccessor memAcce = new MemberAccessor();
					UserData memData = memAcce.GetMemberInfo(list[i].CnfmerID);
					list[i].ConformerName = memData.RealName;
				}
			}
			return list;
		}
		public int SubmitSendGDH(int operater, string strBarCode, string strwldanhao)
		{
			Int64 ubarcode = 0;
			Int64.TryParse(strBarCode, out ubarcode);
			if (strBarCode.Length < 10 || ubarcode < (Int64)89998999)
				return -10;
			SqlParameter[] sqlParameter = {
                 new SqlParameter("@operater",SqlDbType.Int, 4),
                 new SqlParameter("@tiaoma",SqlDbType.BigInt,8),
                 new SqlParameter("@wldanhao",SqlDbType.NVarChar,30),
            };
			sqlParameter[0].Value = operater;
			sqlParameter[1].Value = ubarcode;
			sqlParameter[2].Value = strwldanhao;
			SqlCommand cmd = null;
			int nRet = -8;
			try {
				cmd = new SqlCommand();
				cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
				cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
				nRet = SqlHelper.ExecuteNonQuery(cmd, "CommitSendGoodsDH", sqlParameter);
				int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nRet);
			}
			catch (System.Exception e)
			{
				if (cmd != null)
					cmd.Parameters.Clear();
				String strErr = e.Message;
				nRet = -8;
			}
			return nRet;
		}

		public List<F123HisData> GetNullifyDetail(int nPageIndex, int nPageSize, string strBeginTime, string strEndTime, out int outTotal, string kindmatch)
		{
			List<F123HisData> list = new List<F123HisData>();
			outTotal = 0;
			SqlParameter[] sqlParamenter = { 
				new SqlParameter("@pageIndex",SqlDbType.Int, 4),
				new SqlParameter("@pageSize",SqlDbType.Int, 4),
				new SqlParameter("@begintime",SqlDbType.DateTime, 8),
				new SqlParameter("@endtime",SqlDbType.DateTime, 8),
				new SqlParameter("@kindmatch",SqlDbType.NVarChar, 20),
				new SqlParameter("@outTotalSize",SqlDbType.Int, 4),
            };
			sqlParamenter[0].Value = nPageIndex;
			sqlParamenter[1].Value = nPageSize;
			sqlParamenter[2].Value = null;
			sqlParamenter[3].Value = null;
			sqlParamenter[4].Value = kindmatch;
			sqlParamenter[5].Value = outTotal;
			sqlParamenter[5].Direction = ParameterDirection.Output;
			DateTime bdt, edt;
			if (DateTime.TryParse(strBeginTime, out bdt) && DateTime.TryParse(strEndTime, out edt)){
				sqlParamenter[2].Value = bdt;
				sqlParamenter[3].Value = edt;
			}
			SqlCommand cmd = new SqlCommand();
			cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
			cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
			SqlDataReader read = SqlHelper.ExecuteReader(cmd, "GetNullifyDetail", sqlParamenter);
			bool bNextRDS = true;
			do
			{
				while (read.Read())
				{
					F123HisData info = new F123HisData();
					string strName = string.Empty;
					int nID = 0;
					strName = read["KindName"].ToString();
					int.TryParse(read["nid"].ToString(), out nID);
					if (strName != null || nID != 0)
					{
						info.ID = nID;
						info.KindName = strName;
						Int64 nBarcode = 0;
						Int64.TryParse(read["TiaoMa"].ToString(), out nBarcode);
						info.BarCode = nBarcode;
						DateTime tt;
						strName = read["ApplyTime"].ToString();
						if (DateTime.TryParse(strName, out tt))
							info.ApplyTime = tt;
						info.WLDanHao = read["WLDanHao"].ToString();

						Decimal dmoney = 0;
						strName = read["SingleMoney"].ToString();
						if (Decimal.TryParse(strName, out dmoney))
							info.SingleMoney = dmoney;
						info.MDIntroduction = read["Introduction"].ToString();
						info.MDAddress = read["Address"].ToString();

						list.Add(info);
						bNextRDS = false;
					}
				}
			} while (bNextRDS && read.NextResult());//这里是关键－－－移动到下一个结果集
			read.Close();
			read.Dispose();
			//After Closing, the folowing can get.
			int.TryParse(cmd.Parameters["@outTotalSize"].Value.ToString(), out outTotal);
			int nTmp = 0;
			int.TryParse(cmd.Parameters["@return"].Value.ToString(), out nTmp);
			return list;
		}
	}
}
